package com.hippy.erya.modular.util;

import com.google.common.collect.Lists;
import com.hippy.erya.exception.EyErrorCode;
import com.hippy.erya.exception.EyException;
import org.apache.commons.lang3.StringUtils;

import java.util.List;


public class FileUtils {

    /**
     * 文件上传支持的文件后缀类型
     */
    public static final List<String> FILE_TYPE = Lists.newArrayList("XLS", "XLSX", "XLSM");

    /**
     * 检查上传文件类型
     *
     */
    public static void checkUploadFileType(String uploadFileName) {
        if (StringUtils.isNotEmpty(uploadFileName)) {
            String fileType = uploadFileName.substring(uploadFileName.lastIndexOf('.') + 1);
            if (!FILE_TYPE.contains(fileType.toUpperCase())) {
                throw new EyException(EyErrorCode.EXCEL_FORMAT_NOT_RIGHT,
                        EyErrorCode.EXCEL_FORMAT_NOT_RIGHT.getDesc() + FILE_TYPE);
            }
        }
    }

}
